home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16922 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: ix.netcom.com!news
  2. From: giuliano@ix.netcom.com(Giuliano Carlini)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: static initialization order
  5. Date: 12 Apr 1996 17:30:15 GMT
  6. Organization: Netcom
  7. Message-ID: <4km3v7$7v5@dfw-ixnews6.ix.netcom.com>
  8. References: <Dppwqz.Kt3@undergrad.math.uwaterloo.ca>
  9. NNTP-Posting-Host: lbx-ca5-03.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 12 12:30:15 PM CDT 1996
  11.  
  12. In <Dppwqz.Kt3@undergrad.math.uwaterloo.ca>
  13. sckettle@undergrad.math.uwaterloo.ca (Steve Kettle) writes: 
  14. >
  15. >suppose you have n static objects that depend on each other.  if the
  16. dependancy
  17. >graph is a forest ( a bunch of trees ) ( a tree is a graph with no
  18. cycles ) how
  19. >does one guarantee the correct order of construction? The objects in
  20. question
  21. >could be local to a number of different translation units. 
  22. The draft standard states that static objects within a translation unit
  23. are constructed from top down and destructed bottom up. There is no
  24. specified order for static objects in different translation units, and
  25. the compiler writer may do so arbitrarilly.
  26.  
  27. It would have been nice if C++ provided some mechanism to specify this.
  28.  
  29. In these cases I avoid static objects, and replace them with static
  30. pointers to objects. At startup I initialize the pointers in dependency
  31. order.
  32.  
  33. >that is my first question, second is i've been told that static data
  34. is often
  35. >located in memory addresses beyond the start of the heap.  does this
  36. at all
  37. >contradict the fact that static data is initialzed to 0's at compile
  38. time? 
  39.  
  40. No. I'm not sure about this, but I believe the compiler is free to
  41. place static global objects where ever it chooses in memory. It simply
  42. must gaurantee that by the time main runs - actually a little before
  43. that - that uninitialized static data is set to 0.
  44.  
  45. g
  46.